package com.niuwa.p2p.service.loan.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.dao.loan.LoanDao;
import com.niuwa.p2p.entity.PageQuery;
import com.niuwa.p2p.service.loan.ILoanService;
import com.niuwa.p2p.vo.loan.LoanVo;

/**
 * 放款管理Service
 * 
 * @author houdianbo
 * @Date 2015-04-24
 */
@Service
public class LoanServiceImpl implements ILoanService {
	@Autowired
	private LoanDao loanDao;

	@Override
	public PageBean<LoanVo> selectLoanByParam(Map<String, Object> paramMap) {
		assert paramMap.get(PageQuery.PAGEQUERY) != null;
		String projectNo = String.valueOf(paramMap.get("projectNo"));
		if (projectNo != null) {
			projectNo = projectNo.trim().replaceAll("%", "\\\\%")
					.replaceAll("_", "\\\\_");
		}
		String borrowerName = String.valueOf(paramMap.get("borrowerName"));
		if (borrowerName != null) {
			borrowerName = borrowerName.trim().replaceAll("%", "\\\\%")
					.replaceAll("_", "\\\\_");
		}
		// 总条数
		int totalCount = loanDao.getLoanCountByParam(paramMap);
		PageBean<LoanVo> page = new PageBean<LoanVo>(totalCount);
		// 当前页
		page.setPage(((PageQuery) paramMap.get(PageQuery.PAGEQUERY)).getPage());
		page.setRows(loanDao.selectLoanByParam(paramMap));
		return page;
	}

	public void setLoanDao(LoanDao loanDao) {
		this.loanDao = loanDao;
	}
}
